<style lang="less">
  @import '../styles/common.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div>
    <Row :gutter="10">
      <Card>
        <div class="table-head">
          <!--<Button type="primary" class="Button" @click="ExportData()">导出数据</Button>-->
          <!--<Button type="primary" class="Button" @click="remove()">删除</Button>-->
        </div>
        <Row class="margin-top-10">
          <Table stripe border :columns="columns" :data="data" @on-row-click="onRowData"
                 @on-selection-change="selectionChange"></Table>
        </Row>
        <!--<div style="margin: 10px;overflow: hidden;height: 36px;">
          <div style="float: right;">
            <Page :total="total" :current="page" @on-change="changePage" show-elevator></Page>
          </div>
        </div>-->
      </Card>
      <Modal :width="600" title="详情"
             v-model="showCurrentTableData"
             ok-text="确定"
             cancel-text="取消"
             @on-ok=""
             @on-cancel=""
             class-name="vertical-center-modal"
             class="Modal-Detail-div">
        <Form label-position="top">
          <FormItem label="物品名">
            <div class="dataDetail-div" v-text="dataDetail.asset_type ? dataDetail.asset_type.title : ''"></div>
          </FormItem>
          <FormItem label="数量">
            <div class="dataDetail-div" v-text="dataDetail.asset_count"></div>
          </FormItem>
          <FormItem label="物品编号">
            <div class="dataDetail-div">
              <div v-for="el in dataDetail.asset_number" v-text="el"></div>
            </div>
          </FormItem>
          <FormItem label="申请时间">
            <div class="dataDetail-div" v-text="dataDetail.create_time"></div>
          </FormItem>
          <FormItem label="报修原因">
            <div class="dataDetail-div" v-text="dataDetail.title"></div>
          </FormItem>
          <FormItem label="报修说明">
            <div class="dataDetail-div" v-text="dataDetail.description"></div>
          </FormItem>
          <FormItem label="状态">
            <div class="dataDetail-div">
              <span v-if="dataDetail.status == 'checking'">待审批</span>
              <span v-if="dataDetail.status == 'passed'">已通过</span>
              <span v-if="dataDetail.status == 'rejected'">已驳回</span>
            </div>
          </FormItem>
        </Form>
      </Modal>
    </Row>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import String from '../../libs/mod.string';
  import Modal from '../../libs/mod.Modal';
  export default {
    components: {},
    data () {
      return {
        total: 0,
        page: 1,
        size: 10,
        id: '',
        searchConName: '',
        searchConTel: '',
        showCurrentTableData: false,
        loading: true,
        showCurrentColumns: [],
        editInlineAndCellData: [],
        columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'asset_type',
            title: '物品名',
            render: (h, params) => {
              var title = params.row.asset_type.title;
              return h('div', [
                h('span', title)
              ]);
            }
          },
          {
            key: 'number',
            title: '数量',
          },
          {
            key: 'title',
            title: '报修原因',
          },
          {
            key: 'create_time',
            title: '申请时间',
          },
        ],
        data: [],
        dataDetail: {},
        initTable: [],
        format: Util.constant.format,
        addCurrentTableData: false,
        saveLoading: false,
        ajaxType: 'add',
        addData: {
          description: '',
          type_id: '',
          number: 1,
          approvers: '',
          typeArr: [],
        },
        selectionArr: [],
        approversArr: [],
        TreeData: [],
        checked_dep_arr: [],
        checked_users_arr: [],
      };
    },
    mounted () {
      this.getData();
    },
    methods: {
      getData () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          page: _this.page,
          size: _this.size,
        };
        var params = {
          url: '/asset/repair/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.total = res.rows;
            _this.data = _data;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      handleSearch () {
        var _this = this;
        _this.page = 1;
        var searchConName = _this.searchConName;
      },
      changePage (page) {
        var _this = this;
        console.log('page', page);
        _this.page = page;
        _this.getData();
      },
      onRowData: function (data, index) {
        var _this = this;
        _this.show(index, data);
      },
      show: function (index, data) {
        var _this = this;
        var id = data.asset_type.id;
        _this.id = id;

        var data = {
          id: _this.id,
        };
        var params = {
          url: '/asset/repair/query',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.dataDetail = _data;
            _this.showCurrentTableData = true;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      asyncOK: function () {
        var _this = this;
        _this.showCurrentTableData = false;
      },
      // 列表多选 选中数据
      selectionChange: function (selection) {
        var _this = this;
        _this.selectionArr = selection;
      },
      // 删除
      remove: function () {
        var _this = this;
        var selectionArr = _this.selectionArr;
        if (selectionArr.length == 0) {
          _this.$Message.error('请填选择要删除的数据!');
          return false;
        }
        var selectionIds = [];
        for (var k in selectionArr) {
          if (!selectionArr[k]) {
            continue;
          }
          var id = selectionArr[k].id;
          selectionIds.push(id);
        }
        Modal.confirm(_this, {content: '确定删除选中的信息？'}, function () {
          var data = {
            id: selectionIds,
          };
          var params = {
            url: '/feedback/deleteMultiple',
            type: Util.method.get,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          function _successFun(res) {
            if (res.result == 0) {
              _this.page = 1;
              _this.getData();
            } else {
              _this.$Message.error('删除信息失败!');
            }
          }
        }, function () {
        });
      },
      // 导出
      ExportData: function () {
        var _this = this;
        var fields = [
          {
            field: 'id',
            title: '#',
            type: 'int',
            order: 1,
          },
          {
            field: 'name',
            title: '姓名',
            type: 'varchar',
            order: 2,
          },
          {
            field: 'anonymous',
            title: '是否匿名',
            type: 'varchar',
            order: 3,
          },
          {
            field: 'content',
            title: '内容',
            type: 'varchar',
            order: 4,
          },
          {
            field: 'create_time',
            title: '时间',
            type: 'datetime',
            order: 5,
          },
        ];
        var fieldsStr = Util.toStr(fields);
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          type: 'app-suggest',
          fields: fieldsStr,
        };
        var params = {
          url: '/file/db2excle',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var url = res.data;
            var date = Utils.dateToDateString(new Date());
            Utils.DownloadFile(url, '导出我的资产_' + date + '.xlsx');
          } else {
            _this.$Message.error('导出信息失败!');
          }
        }
      },
    }
  };
</script>
